﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestApplication.usercontrols
{
    /// <summary>
    /// Interaction logic for PluginBarControl.xaml
    /// </summary>

    public partial class PluginBarControl : UserControl
    {
        private Button[] buttons;
        private const int NO_OF_BUTTONS=5;

        public PluginBarControl(WebcamControl element)
        {
            InitializeComponent();

            buttons = new Button[NO_OF_BUTTONS];
            double buttonSpace = (element.WebcamImage.ActualHeight - 100) / NO_OF_BUTTONS;

            for (int i = 0; i < NO_OF_BUTTONS; i++)
            {
                buttons[i] = new Button();
                buttons[i].Background = new ImageBrush(new BitmapImage(new Uri(@"resources\" + "s1.png", UriKind.Relative)));
                buttons[i].Width = 100;
                buttons[i].Height = buttonSpace - 0.2 * buttonSpace;
                buttons[i].Margin = new Thickness(0, 0.1 * buttonSpace, 10, 0.1 * buttonSpace);
                buttons[i].Visibility = Visibility.Hidden;
                buttons[i].FontWeight = FontWeights.Bold;
                buttonStack.Children.Add(buttons[i]);
            }
        }
        public void disableAllButtons(bool enabled)
        {
            foreach (Button b in this.buttonStack.Children)
            {
                b.IsEnabled = enabled;
            }
        }
        public System.Drawing.Rectangle[] getButtonRectangles()
        {
            System.Drawing.Rectangle[] rectangles = new System.Drawing.Rectangle[NO_OF_BUTTONS];
            System.Drawing.Point p;
            Point p2;
            for (int i = 0; i < NO_OF_BUTTONS; i++)
            {
                p2 = buttons[i].TranslatePoint(new Point(0, 0), buttonStack);
                p = new System.Drawing.Point(Convert.ToInt32(p2.X), Convert.ToInt32(p2.Y));
                rectangles[i] = new System.Drawing.Rectangle(p, new System.Drawing.Size(Convert.ToInt32(buttons[i].Width), Convert.ToInt32(buttons[i].Height)));
            }
            return rectangles;
        }
        public bool[] getActiveButtons()
        {
            bool[] active = new bool[NO_OF_BUTTONS];
            for (int i = 0; i < NO_OF_BUTTONS; i++)
                if (buttons[i].Visibility == Visibility.Visible)
                    active[i] = true;
            return active;
        }
    }
}
